package com.java.atm.Account;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.Date;
import java.util.Scanner;
import java.util.Set;

public class Account
{
    public double balance;
    public double rate;
    public Date lastTransion;

    public synchronized void getBalanceStr()//得到当前余额
    {
        System.out.println("You have $" +balance);
    }
    public double getBalance()
    {
        return balance;
    }

    public synchronized boolean withdrawl()throws IOException//取钱
    {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Please enter the amount: $");

        double amount = 0;

        amount = scanner.nextDouble();


        while ((amount < 0) || (balance - amount < 0))
        {
            System.out.println("invalid amount");
            System.out.print("Please enter the amount: $");


            amount = scanner.nextDouble();


        }

        return true;


    }

    public synchronized boolean deposit()throws IOException//存钱
    {
        Scanner s = new Scanner(System.in);
        System.out.print("Please enter the amount: $");

        double amount = 0;
        amount = s.nextDouble();
        while ((amount < 0))
        {
            System.out.println("invalid amount");
            System.out.print("Please enter the amount: $");


            amount = s.nextDouble();


        }
        balance += amount;

        return true;
    }

    public synchronized void getInterest()//计算利息
    {
        balance *= rate;
    }

    public synchronized void setBalance(double balance)
    {
        this.balance = balance;
    }
    public synchronized void setRate(double rate)
    {
        this.rate = rate;
    }
    public synchronized void setLastTransion(Date date)
    {
        this.lastTransion = date;
    }
    public Date getLastTransion()
    {
        return lastTransion;
    }

}
